/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package negocio.dao;

import java.sql.SQLException;
import negocio.HibernateUtil;
import org.hibernate.Session;
import negocio.Horariopista;
import org.hibernate.Query;

/**
 *
 * @author davidcabrera
 */
public class HorariopistaDAO {
    
    Session hSession = null;

    public HorariopistaDAO() {
        this.hSession = HibernateUtil.getSessionFactory().openSession();
    }
    
    public Horariopista read(Integer idpista, Integer idHorario)throws SQLException{
        hSession.clear();
        Query q = hSession.createQuery("from Horariopista where idPista='"+idpista+"' AND idHorario='"+idHorario+"'");
        Horariopista u =  (Horariopista)q.uniqueResult();
        return u;
        
    }
    
    public int delete(Integer idpista, Integer idHorario)throws SQLException{
        hSession.clear();
        String hql = "delete from horariopista where idPista='"+idpista+"' and idHorario='"+idHorario+"'";
        Query query = hSession.createQuery(hql);
        hSession.beginTransaction();
        int rowCount = query.executeUpdate();
        hSession.getTransaction().commit();
        return rowCount;
        
    }
    
}
